package com.sgb.kjwl.view.ui.adapter.self;

import android.app.Activity;
import android.view.View;
import androidx.databinding.ViewDataBinding;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.bumptech.glide.request.RequestOptions;
import com.harisucici.jetpackbase.view.HBaseAdapter;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemJoinCompanyBinding;
import com.sgb.kjwl.model.entity.user.CompanyInfoEntity;

public class JoinCompanyAdapter extends HBaseAdapter<CompanyInfoEntity, ItemJoinCompanyBinding> {

    private JoinCompanyAdapter.BindingListenConfirm confirm;

    public JoinCompanyAdapter(Activity context, JoinCompanyAdapter.BindingListenConfirm<CompanyInfoEntity, ItemJoinCompanyBinding> confirm) {
        super(context);
        this.mContext = context;
        this.confirm = confirm;
    }


    @Override
    protected int getLayoutResId(int viewType) {
        return R.layout.item_join_company;
    }

    @Override
    protected void onBindItem(ItemJoinCompanyBinding binding, CompanyInfoEntity companyInfoEntity, int position) {
        Glide.with(mContext).load(companyInfoEntity.getCompLogo())
                .apply(RequestOptions.bitmapTransform(new CircleCrop()).placeholder(R.drawable.icon_no_logo))
                .into(binding.logoView);

        binding.joinView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                confirm.onItemClick(binding, companyInfoEntity, position);
            }
        });

        binding.setViewModel(companyInfoEntity);
        binding.executePendingBindings();
    }

    @FunctionalInterface
    public interface BindingListenConfirm<T, B extends ViewDataBinding> {
        void onItemClick(B binding, T t, int i);
    }
}
